<template>
	<view class="zai-box">
		<!-- 获取用户信息弹框 -->
		<uni-popup ref="changsuopopup" type="bottom" :mask-click="true">
			<view class="scortop">
				<view class="title">绑定小程序</view>
				<uni-icons type="close" size="30" @click="compcloseTwo"></uni-icons>
			</view>
			<view class="wxbox">
				<view class="padding flex flex-direction">
					<button class="cu-btn lg bg-blue shadow" @tap="getUserProfile">获取用户信息</button>

				</view>

			</view>
		</uni-popup>

	</view>

</template>

<script>
	import server from '@/api/server.js'
	export default {
		props: {
			wxshow: Boolean, // 
			firstclick: {
				type:Boolean,
				default:true,
			}, // 首页第一次进入
		},
		data() {
			return {
				params: {
					id: '',
					wxCode: '',
					wxNkname: '',
				}
			};
		},
		onLoad: function() {

		},
		mounted() {
			this.openmodel()
			// this.getUserProfile()
		},
		computed: {

		},
		methods: {
			openmodel() {
				console.log(this.firstclick, '00000000000000')
				if (!this.firstclick) {
					return
				}
				if (this.wxshow) {
					this.$refs.changsuopopup.open('top')
				}
			},
			compcloseTwo() {
				this.$refs.changsuopopup.close()
			},
			getUserProfile(e) {
				console.log('进入获取code进入获取code进入获取code进入获取code进入获取code')
				// 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
				// 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
				wx.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						console.log(res,'234567876543234567654323456765')
						this.params.wxNkname = res.userInfo.nickName
						this.loginUser()
					}
				})
			},
			//用户登录
			loginUser() {
				console.log(111)
				uni.login({
					provider: 'weixin',
					success: (loginRes) => {
						console.log('用户登录')
						console.log(loginRes)
						this.params.wxCode = loginRes.code; //保存登录后的code
						this.params.id = this.$store.getters.bidderid
						server.appletbind(this.params).then(res => {
							console.log(res, '用户登录用户登录用户登录')
							if (res.data.success) {
								this.$tip.toast(res.data.message)
							}
						}).catch(() => {
							this.$tip.error('身份已过期，请重新登录!')
						});
						// //获取session_key
						// uni.request({
						// 	url: 'https://api.weixin.qq.com/sns/wxCode2session',
						// 	method: 'GET',
						// 	data: {
						// 		appid: 'wxc96dd1da054e2005', //你的小程序的APPID
						// 		secret: '0b59a7053cc0048ab8d3168e791b88b3', //你的小程序秘钥secret,  
						// 		js_code: this.wxCode, //wx.login 登录成功后的code
						// 		grant_type: 'authorization_code'
						// 	},
						// 	success: (cts) => {
						// 		console.log('获取信息', cts); // 换取成功后 暂存这些数据 留作后续操作
						// 		this.openid = cts.data.openid //openid 用户唯一标识
						// 		this.session_key = cts.data.session_key //session_key  会话密钥
						// 	}
						// });



					}
				});
			},
		},

		beforeDestroy() {
			if (this.smsCountInterval) {
				clearInterval(this.smsCountInterval);
			}
		},
	}
</script>

<style scoped lang="scss">
	.cu-form-group {
		padding: 0.5px 15px;
	}

	.login-paddingtop {
		padding-top: 100upx;
	}

	.zai-box {
		padding: 0 20upx;
		padding-top: 100upx;
		position: relative;
	}

	.zai-logo {
		width: 200upx;
		height: 150px;
	}

	.zai-title {
		font-size: 58upx;
		color: #000000;
		text-align: center;
	}

	.input-placeholder,
	.zai-input {
		color: #94afce;
	}

	.zai-label {
		padding: 60upx 0;
		text-align: center;
		font-size: 30upx;
		color: #a7b6d0;
	}

	.zai-btn {
		background: #ff65a3;
		color: #fff;
		border: 0;
		border-radius: 100upx;
		font-size: 36upx;
	}

	.zai-btn:after {
		border: 0;
	}

	/*按钮点击效果*/
	.zai-btn.button-hover {
		transform: translate(1upx, 1upx);
	}

	.registerBox {
		box-shadow: 1px 1px 13px 0px #ccc;
		background-color: white;
		padding: 10px;
		margin-bottom: 10px;


	}

	/deep/.uni-forms-item__label .label-text {
		font-size: 17px !important;
		color: #333333;
	}

	/deep/.grid.grid-square>.solids {
		margin: 0;
	}

	.cu-form-group {
		padding: 10px 15px;
	}


	/deep/uni-page-wrapper {
		background-color: white;
	}

	.zai-box {
		padding: 0;
	}

	.zai-logo {
		width: 165px;
		height: 0;
		margin-top: 60px;
	}

	.cu-form-group uni-input {
		padding-right: 0;
	}

	.cu-form-group {
		text-align: center;
	}

	.text-lg {
		position: absolute;
		right: 14px;
	}

	.placeholdercolor {
		color: #C2C2C2;
	}

	.shadow-warp {
		box-shadow: unset;
		border-bottom: 1px solid #E7E7E7;
	}

	.cu-form-group+.cu-form-group {
		border-top: unset;
	}

	.login-paddingtop {
		padding-top: 38px;
	}

	.logintop {
		margin-top: 40px;
	}

	.wanjiZhu {
		display: flex;
		justify-content: space-between;
		padding-top: 20px;
		width: 100%;
		align-items: center;
		color: #C2C2C2;
	}

	// .wxbox {
	// 	height: 150px;
	// }
</style>
